class TextStyle{
  name = '';
  type = '';
  value;
  displayName = '';
  describe = '';
  constructor(name , type , value , displayName , describe){
    Object.assign(this , {
      name,
      type,
      value,
      displayName
    }),
    this.describe = describe || '';
  }
}

export function resetTitleStyle(current){
  let styles = [
    {name: 'fontSize' , type: 'number' , value: 10 , displayName: '字体大小' , describe: ''},
    {name: 'textIndent' , type: 'number' , value: 0 , displayName: '缩进' , describe: ''},
    {name: 'fontBold' , type: 'boolean' , value: false , displayName: '加粗' , describe: ''},
    {name: 'fontOblique' , type: 'boolean' , value: false , displayName: '倾斜' , describe: ''},
    {name: 'fontColor' , type: 'colorPicker' , value: '#000' , displayName: '字体颜色' , describe: ''},
    {name: 'bgColor' , type: 'colorPicker' , value: 'rgba(255,255,255,0)' , displayName: '背景颜色' , describe: ''}
  ];
  let addlist = [];
  if(current && current.length){
    styles.forEach(
      item => {
        let add = true;
        current.forEach(
          cItem => {
            if(cItem.name == item.name){
              add = false;
            }
          }
        )
        if(add){
          addlist.push(item);
        }
      }
    )
  }else{
    addlist = styles;
  }
  let result = current ? current : [];
  addlist.forEach(
    item => {
      result.push(new TextStyle(item.name , item.type , item.value , item.displayName , item.describe));
    }
  )
  return result;
}

export class WidgetModelPublics{
  title = {
    text: '',
    show: '',
    style: resetTitleStyle(null)
  }
  showOperating = true;
  location = {
    x: 0,
    y: 0,
    w: 4,
    h: 4
  }
}
export class WidgetModel{

  meta = {
    id: '',
    widgeTypeId: '',
    widgetType: '',
    selector: '',
    loadData: true,
    query: {
      dataSource: {
        id: 19,
        name: 'MySql测试数据源',
        type: 'mysql'
      },
      expression: 'select * from datas',
      dictionaryId: ''
    },
    publics: new WidgetModelPublics(),
    variables: [],
    targets: [],
    privates: {},
    dataset: []
  }
  x = 0;
  y = 0;
  h = 4;
  w = 4;
  i = '';



  constructor(initData){
    if(initData){
      Object.assign(this , initData);
    }
  }


}